- /* snfagrup.cpp by K.Tsuru */
- // function ID = 1000 DRADIX
- #ifndef SN_H
- #include "sn.h"
- #endif
- /***************************************************************
- Comparing two values from the position of one, return how many digits
- agree each other.In the case of SDouble the exponent is not considerd
- and the head zeros are not counted.
- If an error ocuured return a negative value as follows.
- not DRADIX : -1
- different type : -2
- not in standard form : -3
- *****************************************************************/
- long AgreeUpTo(const SNumber& a, const SNumber& b){
- if( !a.Sign(1000) && !b.Sign(1000) ) return 1;
- if( (a.Radix() != DRADIX) || (b.Radix() != DRADIX) ) return -1;
- if( a.Type() != b.Type() ) return -2;
- if( (a.Type() == a.REAL) && (!a[1] || !b[1]) ) return -3;
-
- uint top = min(a.Head(), b.Head()) +1, j = 0;
- int at = 0, bt = 0, f, add = 0;
- long same;
-
- while( (j < top) && (a[j] == b[j]) ) j++;
- same = (long)j*DFIGURES;
- if(j < top){
- at = (int)a[j]; bt = (int)b[j];
- }
-
- if(a.Type() == a.REAL){
- add = -2*(int)DFIGURES; // 0.dddd
- if( j > 1 ) add += iFigures(a[1]); //a(1) == b(1), a[1]=0123, b[1]=0123, add+=3
- //It excludes five zeros in 0000.0, add=-5.
- if(at && bt){
- fType r = DRADIX/10;
- //agreeing digits in the last figure
- //at = 1230, bt = 1256 -> 1 == 1, 2 == 2, 3 != 5 : add += 2
- while(r && ( (at/r) == (bt/r) ) ){ r /= 10; add++; }
- }
- } else if(at && bt){
- //agreeing digits in the tail of top figure
- f = abs( at - bt ); // xx00 :number of zeros agree. 5634-1234=4400, add+=2
- while( f && !(f%10) ){ f /= 10; add++; }
- }
- same += add;
- return same > 0 ? same : 0;
- }
snfagrup.cpp : last modifiled at 2017/03/13 14:32:01(1,708 bytes)
created at 2016/04/11 11:36:47
The creation time of this html file is 2017/10/27 10:59:17 (Fri Oct 27 10:59:17 2017).